import {Component, Input, OnInit} from '@angular/core';
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import {UtilComponent} from '../../interface/util-component.interface';


@Component({
    selector: 'kylin-shared-views',
    templateUrl: './shared-views.component.html',
    styleUrls: ['./shared-views.component.less']
})
export class SharedViewsComponent implements OnInit, UtilComponent {
    // ---------- 接口实现 begin -------------- //
    hasContent = true;
    map: Map;
    view: View;
    map2;
    @Input() set data(val) {
        Object.assign(this, val);
    };

    // ---------- 接口实现 end ---------------- //

    layer;
    constructor() {
    }

    ngOnInit() {
        this.map2 = new Map({
            target: this.map.getTarget(),
            layers: this.map.getLayers().getArray(),
            view: this.map.getView(),
        });
    }

    cancel(options?: any): any {
        this.map2.setTarget('');
        this.map2.removeLayer(this.map2.getLayers().getArray());
        this.view =  new View({
            zoom: 5,
            center: [108.943904, 34.319323],
            projection: 'EPSG:3857',
            minZoom: 0
        });
        this.map.setView(this.view)
    }

}
